$(function(){
	//置顶加载
	tmTop.init();
	/* 发表留言  */
	var timer = null;
	$("#tm_sendcomment").click(function(){
		var userid = $("body").data("userid");
		if(isEmpty(userid)){
			tzMessage.tip("请登录!");
			tmLogin.dialog();
			return;
		}else{
			var content = getEditText("myEditor");
			var title = $("#title").val();
			var userId = $("body").data("userid");
			if(isEmpty(title)){
				$("#title").focus();
				tm_showmessage("请输入标题！");
				return;
			}
			if(isEmpty(content)){
				tm_showmessage("请输入内容！");
				UM.getEditor("myEditor").focus();
				return;
			}
			clearTimeout(timer);
			content = getEditoHtml("myEditor");
			timer = setTimeout(function(){
				$.ajax({
					type:"post",
					url:basePath+"/stage/savebook",
					data:{"content":content,"title":title,"userId":userId},
					success:function(data){
						$("#contentbox").prepend(
						" <div class='block photo'>"+
						"		<label style='font-weight: 700;font-size: 18px;'>"+title+"</label>"+
						"              <div class='side'>"+
						"                   <div class='day'><a href='javascript:void(0);'>"+(new Date).format("MM")+"</a></div>"+
						"                   <div class='month'><a href='javascript:void(0);'>"+(new Date).format("dd")+"</a></div>"+
						"              </div>"+
						"              <div class='main'>"+
						"                  <div class='content'>"+content+"</div>"+
						"              <div class='link'>"+
						"                  <a href='javascript:void(0);' data-bookid='${logMap.id}' onclick='tm_comment(this);'>评论(1)</a>"+
						"                  <a href='javascript:void(0);' data-bookid='${logMap.id}' onclick='tm_delete_content(this)'>删除</a>"+
						"              </div>"+
						"		</div>"+
						"       </div>"+
						"   </div>" );
						$("#title").val("");
						$("#content").val("");
						setEditorText("","myEditor");
					}
				});	
			},200);
		}
	});
});

//置顶操作
var tmTop = {
	init:function(){
		$(window).scroll(function(){
			var top = $(this).scrollTop();
			$("#tm_top")[top>200?"show":"hide"]();
		});
		$("#tm_top").click(function(){
			$("html,body").animate({scrollTop:0});
		});	
	}
};
//分页数据加载
var tmOption = {
	pageNo:1,
	pageSize:12,
	mark:true,
	timer:null,
	/********加载和初始化页码*********/
	loadData:function(obj){
		this.load(obj);
		tmOption.pageNo++;
	},
	/********加载查询博客信息*********/
	load:function(obj){
		clearTimeout(tmOption.timer);
		tmOption.timer = setTimeout(function(){//异步处理中--节流
			if(!tmOption.mark)return;
			var pno = tmOption.pageNo * tmOption.pageSize;
			var psize = tmOption.pageSize;
			var params = {pageNo:pno,pageSize:psize};
			$.ajax({
				type:"post",
				url:basePath+"/stage/booklist",
				data:params,
				success:function(data){
					if(data&&data.length>0){
						var html = "";
						for(var i = 0;i<data.length;i++){
							var book = data[i];
							html+="<div class='block photo'>"+
								"	<label style='font-weight: 700;font-size: 18px;'>"+book.title+"</label>"+
								"	<div class='side'>"+
								"		<div class='day'><a href='javascript:void(0);'>"+(new Date(book.createTime)).format("MM")+"</a></div>"+
								"		<div class='month'><a href='javascript:void(0);'>"+(new Date(book.createTime)).format("dd")+"</a></div>"+
								"	</div>"+
								"	<div class='main'>"+
								"		<div class='content'>"+book.content+"</div>"+
								"		<div class='link'>"+
								"			<a href='javascript:void(0);' data-bookid='"+book.id+"' onclick='tm_comment(this);'>评论(1)</a> "+
								"			<a href='javascript:void(0);' data-bookid='"+book.id+"' onclick='tm_delete_content(this)'>删除</a>"+
								"		</div>"+
								"	</div>"+
								"</div>";
						}
						$("#contentbox").append(html);
					}else{
						tmOption.mark = false;
							$(obj).removeAttr("onclick").find(".text").html("数据加载完毕...");
	 					}
					}
				});
			
		},1000);
		
	},
		
	save:function(){
		
	},
	
	comment:function(){
		
	},
	
	update:function(){
		
	},
	
	del:function(){
		
	},
	
	search:function(){
		
	}
};